import { defineConfig, externalizeDepsPlugin, loadEnv } from 'electron-vite'
import { getSrcPath } from './build/utils'
import { createVitePlugins } from './build/plugin'
import { viteDefine } from './build/config'
import { join } from 'path'

export default defineConfig(({ command, mode }) => {
  const isBuild = command === 'build'
  const viteEnv = loadEnv(mode, undefined, 'VITE') as unknown as ImportMetaEnv
  console.log(command, isBuild, viteEnv, getSrcPath())

  return {
    main: {
      resolve: {},
      plugins: [externalizeDepsPlugin()]
    },
    preload: {
      plugins: [externalizeDepsPlugin()]
    },
    renderer: {
      resolve: {
        alias: {
          '@': join(getSrcPath(), 'renderer', 'src')
        }
      },
      define: viteDefine,
      plugins: createVitePlugins(viteEnv, isBuild)
    }
  }
})
